package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ActivityCouponsUser;
import com.sc.nft.entity.MallOrderRefund;
import com.sc.nft.enums.MemberEquityTemplateeceiveCycleEnum;
import com.sc.nft.mapper.ActivityCouponsUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 优惠券领取记录dao
 *
 * @author liGen
 * @version 1.0
 * @date 2023/12/5 4:27 下午
 */
@Slf4j
@Repository
public class ActivityCouponsUserDao extends ServiceImpl<ActivityCouponsUserMapper, ActivityCouponsUser> {

    /**
     * 获取优惠券活动下用户的领取记录
     *
     * @param activityCouponsId
     * @param userId
     * @return
     */
    public List<ActivityCouponsUser> getByUserIdAndActivityCouponsId(Long activityCouponsId, Long userId, Long mallMemberEquityId, Date startTime, Date endTime) {
        LambdaQueryWrapper<ActivityCouponsUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityCouponsUser::getUserId, userId);
        wrapper.eq(ActivityCouponsUser::getActivityCouponsId, activityCouponsId);
        if (Objects.nonNull(mallMemberEquityId)) {
            wrapper.eq(ActivityCouponsUser::getMallMemberEquityId, mallMemberEquityId);
            wrapper.between(ActivityCouponsUser::getCreateTime, startTime, endTime);
        }
        return baseMapper.selectList(wrapper);
    }
}
